package com.algorithm

fun removeDuplicates1(nums: IntArray): Int {
    if (nums.size == 0) return 0
    var i = 0
    for (j in 1 until nums.size) {
        println("nums[$j]= ${nums[j]} nums[$i]=${nums[i]} ")

        if (nums[j] != nums[i]) {
            i++
            println("i++ =$i")
            nums[i] = nums[j]
        }
    }


    return i + 1
}

fun countAndSay(n: Int): String {
    if(n==1) return "1"
    if(n>1) {
        var result = countAndSay(n-1)
        if(result.length==1){
            return "1$result"
        }

        var count = 0
        var stringBuffer  = StringBuffer()
        for(i in 1 until result.length){
            var pre = result[i-1].toInt()
            var tmp = result[i].toInt()
            if(pre == tmp){
                count ++
            }else{
                stringBuffer.append(count.toString()).append(pre)
                count == 0
            }
        }
        return stringBuffer.toString()
    }
    return ""
}